package com.zhijian.medical.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhijian.medical.entity.po.ExperimentFishAnJieguo;
import com.zhijian.medical.dao.local.FishAnShiJieguoMapper;
import com.zhijian.medical.enums.ResponseCodeEnum;
import com.zhijian.medical.exception.BusinessException;
import com.zhijian.medical.service.FishAnShiJieguoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author li xiao dong
 * @since 2022-08-12
 */
@Service
public class FishAnShiJieguoServiceImpl extends ServiceImpl<FishAnShiJieguoMapper, ExperimentFishAnJieguo> implements FishAnShiJieguoService {
    @Autowired
    private FishAnShiJieguoMapper anJieguoMapper;

    @Override
    public Boolean deleteByFishId(Long fishId) {
        QueryWrapper<ExperimentFishAnJieguo> experimentFishAnJieguoQueryWrapper = new QueryWrapper<>();
        experimentFishAnJieguoQueryWrapper.eq("fish_id", fishId);
        return anJieguoMapper.delete(experimentFishAnJieguoQueryWrapper) > 0;
    }

    @Override
    public Boolean insert(ExperimentFishAnJieguo experimentFishAnJieguo) {
        int count = anJieguoMapper.insert(experimentFishAnJieguo);
        if (count <= 0) {
            throw new BusinessException(ResponseCodeEnum.FAILURE.code, "暗室创建失败");
        }
        return true;
    }

    @Override
    public List<ExperimentFishAnJieguo> list(Long fishId) {
        QueryWrapper<ExperimentFishAnJieguo> experimentFishAnJieguoQueryWrapper = new QueryWrapper<>();
        experimentFishAnJieguoQueryWrapper.eq("fish_id", fishId);
        return anJieguoMapper.selectList(experimentFishAnJieguoQueryWrapper);
    }
}
